const utility = require("utility");
const { verify } = require("jsonwebtoken");

async function userInfo(data) {
    let selectSql = `SELECT * FROM user WHERE id="${data.userId}" `;
    try {
        const selectRows = await global.sql(selectSql)
        if (selectRows.status) {
            const userInfoData = selectRows.data[0]
            delete userInfoData.password
            return {
                code: 200,
                msg: '请求成功',
                data: userInfoData
            }
        } else {
            return {
                code: 500,
                msg: '服务器繁忙',
                data: null
            }
        }
    } catch (err) {
        return {
            code: 500,
            msg: '服务器繁忙',
            data: null
        }
    }
}

// 分页查询历史纪录
async function getHistoryList(data) {
    const offset = (data.pageNumber - 1) * 10;
    let selectSql = `SELECT * FROM history WHERE userId = ${data.userId} ORDER BY createTime ASC LIMIT ? OFFSET ?`;
    const qlParams = [10, offset];
    let selectRows = await global.sql(selectSql, qlParams)
    if (selectRows.status) {
        return {
            code: 200,
            msg: '请求成功',
            data: selectRows.data
        }
    } else {
        return {
            code: 500,
            msg: '服务繁忙',
            data: null
        }
    }
}



exports.userInfo = userInfo
exports.getHistoryList = getHistoryList

